<div class="header">
    <div class="wrapper clearfix">
        <div class="fl">
            <a href="/"><img src="<?= $this->__STATIC__ ?>images/logo.png" class="logo" width="35"></a>
            <a href="/">首页</a>
            <?php
            if (!$this->userSession):
            ?>
            <a href="javascript:;" class="login-btn">登录</a>
            <?php
            else:
            ?>
            <a href="/product/list" class="pro-btn">产品中心</a>
            <a href="javascript:;" id="out-btn">退出</a>
            <?php
            endif;
            ?>
        </div>
        <div class="nav">
            <ul class="clearfix">
                <li>
                    <?php
                    if (!$this->userSession):
                        ?>
                        <a href="javascript:;" class="register-btn">PATTERN 图库体验</a>
                        <dl>
                            <dd><a href="javascript:;" class="register-btn">注册体验</a></dd>
                            <dd><a href="javascript:;" class="login-btn">立即登录</a></dd>
                        </dl>
                        <?php
                    else:
                        ?>
                        <a href="/product/list" class="pro-btn">PATTERN 图库体验</a>
                        <?php
                    endif;
                    ?>
                </li>
                <li>
                    <a href="/introduce/index/">PATTERN 图库介绍</a>
                    <dl>
                        <dd><a href="/introduce/detail/">图库详情</a></dd>
                        <dd><a href="/introduce/advantage/">图库优势</a></dd>
                        <dd><a href="/introduce/buy/">购买方式</a></dd>
                    </dl>
                </li>
                <li>
                    <a href="/book/index/">图库素材书</a>
                    <dl>
                        <dd><a href="/book/pattern/">PATTERN</a></dd>
                        <dd><a href="/book/patternII/">PATTERN II</a></dd>
                        <dd><a href="/book/essential/">PATTERN<br><small>essential</small></a></dd>
                        <dd><a href="/book/buy/">购买方式</a></dd>
                    </dl>
                </li>
                <li>
                    <a href="/area/index/">服务领域</a>
                    <!--
                    <dl>
                        <dd><a href="/area/index#item1">服饰图案</a></dd>
                        <dd><a href="/area/index#item2">家居图案</a></dd>
                        <dd><a href="/area/index#item3">消费品图案</a></dd>
                        <dd><a href="/area/index#item4">广告平面设计</a></dd>
                        <dd><a href="/area/index#item5">其他图案定制</a></dd>
                    </dl>
                    -->
                </li>
                <li>
                    <a href="/items/index/">服务项目</a>
                    <!--
                    <dl>
                        <dd><a href="/items/index#item1">产品企划</a></dd>
                        <dd><a href="/items/index#item2">图案设计</a></dd>
                        <dd><a href="/items/index#item3">设计顾问</a></dd>
                    </dl>
                    -->
                </li>
                <li><a href="/about/index/">公司简介</a></li>
                <li><a href="/contact/index/">联系我们</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="black"></div>
<div class="login register-div">
    <a href="javascript:;" class="close">×</a>
    <div class="box">
        <center><img src="<?= $this->__STATIC__ ?>images/logo.jpg" width="80"></center>
        <h3>欢迎使用PATTERN图库体验版</h3>
        <form>
            <div class="input">
                <input type="text" id="name" placeholder="真实姓名">
            </div>
            <div class="input">
                <input type="password" id="pwd" placeholder="登录密码">
            </div>
            <div class="input">
                <input type="password" id="re-pwd" placeholder="确认密码">
            </div>
            <div class="input">
                <input type="text" id="company" placeholder="所属公司全称">
            </div>
            <div class="input">
                <input type="text" id="mobile" placeholder="联系手机">
                <a id="sendCode" href="javascript:;">获取验证码</a>
            </div>
            <div class="input">
                <input type="text" id="mobile-code" placeholder="手机验证码">
            </div>
            <input type="button" id="sub-btn" value="立即注册">
        </form>
    </div>
</div>
<div class="login login-div">
    <a href="javascript:;" class="close">×</a>
    <div class="box">
        <center><img src="<?= $this->__STATIC__ ?>images/logo.jpg" width="80"></center>
        <h3>欢迎使用PATTERN图库体验版</h3>
        <form>
            <div class="input">
                <input type="text" id="login-name" placeholder="真实姓名">
            </div>
            <div class="input">
                <input type="password" id="login-pwd" placeholder="登录密码">
            </div>
            <input type="button" id="login-now" value="立即登录">
        </form>
        <div class="ts">
            <p>
                <img src="<?= $this->__STATIC__ ?>images/icon01.png" width="24">
                真还不是会员？<a href="javascript:;" class="register-btn">立即注册</a>
            </p>
            <h5>想购买 PATTERN 图库正式版</h5>
            <p>
                <img src="<?= $this->__STATIC__ ?>images/icon02.png" width="24">
                售前咨询热线：13661765690
            </p>
            <p>
                <img src="<?= $this->__STATIC__ ?>images/icon03.png" width="24">
                售前咨询微信：yibai-h-uno100
            </p>
        </div>
    </div>
</div>
<script>
    var clickState = true;
    var that = this;
    // var regPwd = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
    var myreg = /^1\d{10}$/;
    var regPwd = /^[a-zA-Z]\w{5,17}$/;
    var countdown = 60;
    //获取短信验证码
    $("#sendCode").click(function () {
        var mobile = $('#mobile').val();
        console.log(mobile);
        if (mobile == '') {
            alert('手机号码不能为空');
            return false;
        } else if (mobile.length!=11) {
            alert('请输入有效的手机号码，需是11位！');
            return false;
        } else if (!myreg.test(mobile)) {
            alert('请输入有效的手机号码！');
            return false;
        } else {
            if(clickState){
                sendRegisterCode(mobile);
            }
        }
    });

    function sendRegisterCode(mobile) {
        $.post('/api/common/sendMobileCode', {
            'mobile': mobile, 'type': 0
        }, function (data) {
            console.log(data);
            switch (parseInt(data.errcode)) {
                case 0:
                    console.log(data.rsp);
                    clickState = false;
                    settimeRegister(mobile);
                    break;
                default :
                    alert(data.errmsg);
                    return;
                    break;
            }
        }, 'json');
        return true;
    };

    function settimeRegister(mobile) {
        if (countdown == 0) {
            $("#sendCode").html("获取短信验证码");
            countdown = 60;
            $('#sendCode').bind('click', function () {
                sendRegisterCode(mobile);
            });
            return;
        } else {
            $("#sendCode").html("重新发送(" + countdown + "s)");
            countdown--;
            $("#sendCode").unbind('click');
        }
        setTimeout(function () {
            settimeRegister(mobile);
        }, 1000);
    };

    //提交注册信息
    $('#sub-btn').click(function () {
        var clickState = true;
        var name = $('#name').val();
        var pwd = $('#pwd').val();
        var rePwd = $('#re-pwd').val();
        var company = $('#company').val();
        var mobile = $('#mobile').val();
        var mobileCode = $('#mobile-code').val();
        if (name == '') {
            alert('请填写真实姓名!');
            return false;
        } else if (pwd == '') {
            alert('请填写登录密码!');
            return false;
        } else if (rePwd == '') {
            alert('请填写确认密码!');
            return false;
        } else if (pwd != rePwd) {
            alert('确认密码和登录密码不一致!');
            return false;
        } else if (company == '') {
            alert('请填写公司全称!');
            return false;
        } else if (mobile == '') {
            alert('手机号码不能为空!');
            return false;
        } else if (mobile.length!=11) {
            alert('请输入有效的手机号码，需是11位！');
            return false;
        } else if (!myreg.test(mobile)) {
            alert('请输入有效的手机号码！');
            return false;
        } else if (mobileCode == '') {
            alert('请填写验证码!');
            return false;
        } else {
            console.log(clickState);
            if(clickState){
                $.post('/api/member/register', {
                    name: name,
                    pwd: pwd,
                    rePwd: rePwd,
                    company: company,
                    mobile: mobile,
                    mobileCode: mobileCode,
                    },
                    function(data) {
                        switch (data.errcode) {
                            case 0:
                                console.log(data.rsp);
                                alert('恭喜,注册成功啦!');
                                location.href='/';
                                clickState = false;
                                break;
                            default :
                                clickState = false;
                                alert(data.errmsg);
                                break;
                        }
                    }, 'json');
            }
        }

    })

    //登录
    $('#login-now').click(function () {
        var name = $('#login-name').val();
        var password = $('#login-pwd').val();
        if (name == '') {
            alert('请填写真实姓名!');
            return false;
        } else if (pwd == '') {
            alert('请填写登录密码!');
            return false;
        } else {
            $.post('/api/member/login', {
                'name': name,
                'password': password
                },
                function(data) {
                    switch (data.errcode) {
                        case 0:
                            console.log(data.rsp);
                            alert('登录成功!');
                            location.reload();
                            break;
                        default :
                            alert(data.errmsg);
                            break;
                    }
                }, 'json');
        }
    })

    //退出登录
    $('#out-btn').click(function () {
        $.post('/api/member/loginOut', {},
            function(data) {
                switch (data.errcode) {
                    case 0:
                        console.log(data.rsp);
                        alert('退出成功!');
                        location.reload();
                        break;
                    default :
                        alert(data.errmsg);
                        break;
                }
            }, 'json');
    })

</script>

